package com.sosolabs.com.site.client.view;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

import com.google.gwt.cell.client.AbstractCell;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.resources.client.ClientBundle;
import com.google.gwt.resources.client.ImageResource;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiFactory;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiTemplate;
import com.google.gwt.user.cellview.client.CellBrowser;
import com.google.gwt.user.cellview.client.CellTree;
import com.google.gwt.user.client.ui.AbstractImagePrototype;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.view.client.ListDataProvider;
import com.google.gwt.view.client.MultiSelectionModel;
import com.google.gwt.view.client.SelectionChangeEvent;
import com.google.gwt.view.client.SingleSelectionModel;
import com.sosolabs.com.site.client.view.CellTreeView.Contact;
import com.sosolabs.com.site.client.view.ContactTreeViewModel;
import com.sosolabs.com.site.client.presenter.CellBrowserPresenter;


public class CellBrowserView extends Composite implements CellBrowserPresenter.Display {

	@UiTemplate("ui/CellBrowserView.ui.xml")
	interface Binder extends UiBinder<Widget, CellBrowserView> {
	}

	private static Binder binder = GWT.create(Binder.class);

	@UiField
	Button confirmButton;
	
	@UiField
	TextBox name;
	
	@UiField
	CellBrowser cellBrowser;
	
	@UiField
	TextBox address;

	ListDataProvider<Contact> dataProvider;
	
	Contact cont ;
	
	@UiFactory CellBrowser makeCellBrowser() {
		
		 final SingleSelectionModel<Contact> selectionModel =
		      new SingleSelectionModel<Contact>();
		    selectionModel.addSelectionChangeHandler(
		        new SelectionChangeEvent.Handler() {
		          public void onSelectionChange(SelectionChangeEvent event) {
		            name.setText(selectionModel.getSelectedObject().name);
		            address.setText(selectionModel.getSelectedObject().address);
		          }
		        });

		   
		    ContactTreeViewModel model = new ContactTreeViewModel(selectionModel);
		    cellBrowser = new CellBrowser(
		            new ContactTreeViewModel(selectionModel), null);
		    cellBrowser.setAnimationEnabled(true);

		return cellBrowser;
		
	}
	
	static interface Images extends ClientBundle {
	    ImageResource contact();
	  }

	  
	public CellBrowserView() {
		initWidget(binder.createAndBindUi(this));
	}
	
	public HasClickHandlers getConfirmButton() {
		return confirmButton;
	}
	
	public Widget asWidget() {
		return this;
	}
}
